package com.yezi.lampcourt.ui.presenter;

import android.content.Context;

import com.yezi.lampcourt.base.BaseEntity;
import com.yezi.lampcourt.base.BaseObserver;
import com.yezi.lampcourt.base.BasePresenter;
import com.yezi.lampcourt.entity.ExecuteResultLampBean;
import com.yezi.lampcourt.entity.LampBean;
import com.yezi.lampcourt.entity.ModeBean;
import com.yezi.lampcourt.http.HttpFactory;
import com.yezi.lampcourt.http.LampCourtService;
import com.yezi.lampcourt.http.RxSchedulers;
import com.yezi.lampcourt.ui.contract.CourtContract;

import java.util.List;

/**
 * Created by HongMing Ye
 * on 2017/10/9 0009.
 */

public class CourtPresenter extends BasePresenter<CourtContract.CourtView> implements CourtContract.CourtPresenterInterface {
    public CourtPresenter(Context context, CourtContract.CourtView view) {
        super(context, view);
    }

    @Override
    public void getLampList(String id) {
        HttpFactory.createNormalService(LampCourtService.class)
                .getLampListByCourt(id)
                .compose(RxSchedulers.<BaseEntity<List<LampBean>>>io_main())
                .subscribeWith(new BaseObserver<List<LampBean>>(mContext) {
                    @Override
                    protected void onHandleSuccess(List<LampBean> lampBeanList) {
                        mView.getLampListSuccess(lampBeanList);
                    }

                    @Override
                    protected void onHandleError(String msg) {
                        mView.getLampListFail(msg);
                    }
                });
    }

    @Override
    public void getModeList() {
        HttpFactory.createNormalService(LampCourtService.class)
                .getModeList()
                .compose(RxSchedulers.<BaseEntity<List<ModeBean>>>io_main())
                .subscribeWith(new BaseObserver<List<ModeBean>>(mContext) {
                    @Override
                    protected void onHandleSuccess(List<ModeBean> modeBeen) {
                        mView.getLampModeSuccess(modeBeen);
                    }

                    @Override
                    protected void onHandleError(String msg) {
                        mView.getLampModeFail(msg);
                    }
                });
    }

    @Override
    public void executeMode(String jzqId, String modeId) {
        HttpFactory.createNormalService(LampCourtService.class)
                .executeMode(jzqId, modeId)
                .compose(RxSchedulers.<BaseEntity<List<ExecuteResultLampBean>>>io_main())
                .subscribeWith(new BaseObserver<List<ExecuteResultLampBean>>(mContext) {
                    @Override
                    protected void onHandleSuccess(List<ExecuteResultLampBean> executeResultLampBeen) {
                        mView.executeModeSuccess(executeResultLampBeen);
                    }

                    @Override
                    protected void onHandleError(String msg) {
                        mView.executeModeFail(msg);
                    }
                });
    }
}
